Hệ thống sổ địa chỉ đơn giản trong PHP

1 <?php
2 /*
3  * @author Shahrukh Khan
4  * @website http://www.thesoftwareguy.
in
5  * @facebbok https://www.facebook.com/Thesoftwareguy7
6  * @twitter https://twitter.com/thesoftwareguy7
7  * @googleplus https://plus.google.com/+thesoftwareguyIn
8  */

9 require_once
'./config.php';
10 include
'./header.php';
11 /*******PAGINATION CODE STARTS*****************/

12 if
(!(isset($_GET['pagenum']))) {
13   $pagenum =
1;
14 }
else {
15   $pagenum = $_GET[
'pagenum'];
16 }
17 $page_limit = ($_GET[
"show"] <> "" && is_numeric($_GET["show"]) ) ? $_GET["show"] : 8;
18
19
20 try
{
21   $keyword = trim($_GET[
"keyword"]);
22   
if ($keyword <> "" ) {
23     $sql =
"SELECT * FROM tbl_contacts WHERE 1 AND "
24             .
" (first_name LIKE :keyword) ORDER BY first_name ";
25     $stmt = $DB->prepare($sql);
26     
27     $stmt->bindValue(
":keyword", $keyword."%");
28     
29   }
else {
30     $sql =
"SELECT * FROM tbl_contacts WHERE 1 ORDER BY first_name ";
31     $stmt = $DB->prepare($sql);
32   }
33   
34   $stmt->execute();
35   $total_count = count($stmt->fetchAll());
36
37   $last = ceil($total_count / $page_limit);
38
39   
if ($pagenum < 1) {
40     $pagenum =
1;
41   } elseif ($pagenum > $last) {
42     $pagenum = $last;
43   }
44
45   $lower_limit = ($pagenum -
1) * $page_limit;
46   $lower_limit = ($lower_limit <
0) ? 0 : $lower_limit;
47
48
49   $sql2 = $sql .
" limit " . ($lower_limit) . " , " . ($page_limit) . " ";
50   
51   $stmt = $DB->prepare($sql2);
52   
53   
if ($keyword <> "" ) {
54     $stmt->bindValue(
":keyword", $keyword."%");
55    }
56    
57   $stmt->execute();
58   $results = $stmt->fetchAll();
59 }
catch (Exception $ex) {
60   echo $ex->getMessage();
61 }

62 /*******PAGINATION CODE ENDS*****************/

63 ?>
64 <div
class="row">
65 <?php
if ($ERROR_MSG <> "") { ?>
66     <div
class="alert alert-dismissable alert-<?php echo $ERROR_TYPE ?>">
67       <button data-dismiss=
"alert" class="close" type="button">×</button>
68       <p><?php echo $ERROR_MSG; ?></p>
69     </div>
70 <?php } ?>
71
72   <div
class="panel panel-primary">
73     <div
class="panel-heading">
74       <h3
class="panel-title">Address Book</h3>
75     </div>
76     <div
class="panel-body">
77
78       <div
class="col-lg-12" style="padding-left: 0; padding-right: 0;" >
79         <form action=
"index.php" method="get" >
80         <div
class="col-lg-6 pull-left"style="padding-left: 0;" >
81           <span
class="pull-left">
82             <label
class="col-lg-12 control-label" for="keyword" style="padding-right: 0;">
83               <input type=
"text" value="<?php echo $_GET["keyword"]; ?>" placeholder="search by first name" id="" class="form-control" name="keyword" style="height: 41px;">
84             </label>
85             </span>
86           <button
class="btn btn-info">search</button>
87         </div>
88         </form>
89         <div
class="pull-right" ><a href="contacts.php"><button class="btn btn-success"><span class="glyphicon glyphicon-user"></span> Add New Contact</button></a></div>
90       </div>
91
92       <div
class="clearfix"></div>
93 <?php
if (count($results) > 0) { ?>
94 <script
async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
95 <!-- responsivenoida -->
96 <ins
class="adsbygoogle"
97      style=
"display:block"
98      data-ad-client=
"ca-pub-5139634720777851"
99      data-ad-slot=
"2364206017"
100      data-ad-format=
"auto"
101      data-full-width-responsive=
"true"></ins>
102 <script>
103 (adsbygoogle = window.adsbygoogle || []).push({});
104 </script><br>
105
106         <div
class="table-responsive">
107           <table
class="table table-striped table-hover table-bordered ">
108             <tbody><tr>
109                 <th>Avatar</th>
110                 <th>First Name</th>
111                 <th>Last Name</th>
112                 <th>Contact No #
1 </th>
113                 <th>Email </th>
114                 <th>Action </th>
115
116               </tr>
117   <?php
foreach ($results as $res) { ?>
118                 <tr>
119                   <td style=
"text-align: center;">
120                 <?php $pic = ($res[
"profile_pic"] <> "" ) ? $res["profile_pic"] : "no_avatar.png" ?>
121                     <a href=
"profile_pics/<?php echo $pic ?>" target="_blank"><img src="profile_pics/<?php echo $pic ?>" alt="" width="50" height="50" ></a>
122                   </td>
123                   <td><?php echo $res[
"first_name"]; ?></td>
124                   <td><?php echo $res[
"last_name"]; ?></td>
125                   <td><?php echo $res[
"contact_no1"]; ?></td>
126                   <td><?php echo $res[
"email_address"]; ?></td>
127                   <td>
128                     <a href=
"view_contacts.php?cid=<?php echo $res["contact_id"]; ?>"><button class="btn btn-sm btn-info"><span class="glyphicon glyphicon-zoom-in"></span> View</button></a>&nbsp;
129                     <a href=
"contacts.php?m=update&cid=<?php echo $res["contact_id"]; ?>&pagenum=<?php echo $_GET["pagenum"]; ?>"><button class="btn btn-sm btn-warning"><span class="glyphicon glyphicon-edit"></span> Edit</button></a>&nbsp;
130                     <a href=
"process_form.php?mode=delete&cid=<?php echo $res["contact_id"]; ?>&keyword=<?php echo $_GET["keyword"]; ?>&pagenum=<?php echo $_GET["pagenum"]; ?>" onclick="return confirm('Are you sure?')"><button class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-remove-circle"></span> Delete</button></a>&nbsp;
131                   </td>
132                 </tr>
133   <?php } ?>
134             </tbody></table>
135             <script
async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
136 <!-- responsivenoida -->
137 <ins
class="adsbygoogle"
138      style=
"display:block"
139      data-ad-client=
"ca-pub-5139634720777851"
140      data-ad-slot=
"2364206017"
141      data-ad-format=
"auto"
142      data-full-width-responsive=
"true"></ins>
143 <script>
144 (adsbygoogle = window.adsbygoogle || []).push({});
145 </script><br>
146
147         </div>
148         <div
class="col-lg-12 center">
149           <ul
class="pagination pagination-sm">
150   <?php
151   
//Show page links
152   
for ($i = 1; $i <= $last; $i++) {
153     
if ($i == $pagenum) {
154       ?>
155                 <li
class="active"><a href="javascript:void(0);" ><?php echo $i ?></a></li>
156                 <?php
157               }
else {
158                 ?>
159                 <li><a href=
"index.php?pagenum=<?php echo $i; ?>&keyword=<?php echo $_GET["keyword"]; ?>" class="links" onclick="displayRecords('<?php echo $page_limit; ?>', '<?php echo $i; ?>');" ><?php echo $i ?></a></li>
160                 <?php
161               }
162             }
163             ?>
164           </ul>
165         </div>
166
167           <?php }
else { ?>
168         <div
class="well well-lg">No contacts found.</div>
169 <?php } ?>
170     </div>
171   </div>
172 </div>
173       <?php
174       include
'./footer.php';
175       ?>


Gõ tìm kiếm nhanh...